home *** CD-ROM | disk | FTP | other *** search
- # Miscellaneous Z-Script sample functions
-
- function show_all_subjs() {
- msg_list + $*
- pick -s $[%s] | save +$[%s]:1
- if X$output == X
- eval -p error "Error trying to find messages with subject\n$[%s]"
- else
- open +[$%s]:1
- endif
- }
- button "All Subjects" show_all_subjs
-
- function gui_edit_msg() {
- copy $1 /tmp/msg$1.$$ | delete
- sh $window_shell $visual /tmp/msg$1.$$
- merge /tmp/msg$1.$$
- }
- function loop_edit_msg() {
- foreach msg $* 'gui_edit_msg $msg'
- }
- button "Edit Message" loop_edit_msg
-
- function backtrack() {
- pick -r ^-. -1 -h message-id $* | mark
- return 0
- }
-
- function prev_reference() {
- msg_list - $* # set current message
- unmark * # clear temporary marks
- foreach ref ($[%?references?]) 'backtrack $ref'
- msg_list `:m`
- if "X$output" == X
- error "No previous reference found."
- else
- unmark `:m` | pick -1
- endif
- }
-
- function read_prev_ref() {
- prev_reference $*
- if $status == 0
- read $output
- endif
- }
- button "Previous Reference" read_prev_ref
-
- function create_alias() {
- msg_list - $* # Make sure current message is set
- set name="$[%n]" address="$[%f]" # Grab name and From: from message
- if "X$name" == X
- ask -i name \
- "Can't find this sender's name.\nWhat should I call the alias?"
- if $status != 0
- return -1
- endif
- endif
- alias $name:1 "$address" # alias person's first name to his address
- }
- button CreateAlias create_alias
-
- function use_as_composition() {
- #%
- # use_as_composition [messagelist]
- #
- # Use each of the messages in messagelist (or the current message) as the
- # headers and body of a new composition. Creates one composition for each
- # message in the list. If attached to a GUI button, the selected messages
- # from the Main Window Message Summaries are used.
- #%
- msg_list $*
- foreach msg $output 'copy -f $msg /tmp/draft$$ ; mail -draft /tmp/draft$$'
- sh rm /tmp/draft$$
- }
- button "Use As Composition" use_as_composition
-
- function msg_diff() {
- #%
- # msg_diff [messagelist]
- #
- # Run the "diff" program on the two messages and display the result.
- # If more than two messages are passed to this function, the first and
- # last in the list are compared.
- #%
- if $?input
- set - $input
- endif
- pick +1 -r $* | write -f /tmp/msg$$ | flags -S
- pick -1 -r $* | Pipe "diff - /tmp/msg$$ > /tmp/diff$$"
- page /tmp/diff$$
- sh rm /tmp/diff$$ /tmp/msg$$
- }
- button Diff msg_diff
-
- function set_reply_to() {
- #%
- # set_reply_to [message-number]
- #
- # Sets the varible "$reply_to" to the reply address taken from the
- # indicated message. BUG: Does not attempt to track $reply_to_hdr.
- #%
- msg_list - $1
- unset reply_to
- if $?[%?reply-to?]
- set reply_to = "$[%?reply-to?]"
- else
- if $?[%?from?]
- set reply_to = "$[%?from?]"
- else
- if $?[%?return-path?]
- set reply_to = "$[%?return-path?]"
- endif
- endif
- endif
- }
-
- function collect_addrs() {
- set_reply_to $1
- if $?reply_to
- if $?addrs
- # Fast test for "Did I already use this address?"
- # Not always correct, but errs conservatively.
- if "$addrs" !~ *"$reply_to"*
- set addrs = "$addrs, $reply_to"
- endif
- else
- set addrs = "$reply_to"
- endif
- endif
- return 0
- }
-
- function alias_to() {
- #%
- # alias_to message-numbers alias-name
- #
- # Create an alias named alias-name that maps to the senders
- # of all the listed message-numbers.
- #%
- unset addrs msgs
- shift -m | set msgs
- if $?msgs
- each $msgs collect_addrs
- else
- error "usage: alias_to message-numbers alias-name"
- return -1
- endif
- if $# == 0
- ask -i name "Enter name for alias:"
- if $status != 0
- return
- endif
- else
- set name = "$*"
- endif
- alias "$name" "$addrs"
- unset addrs msgs name reply_to
- }
- button "Alias To" alias_to
-